/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.front.web;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.account.service.AccountService;
import com.jeeplus.modules.dynamicrecord.service.DynamicRecordService;
import com.jeeplus.modules.member.service.MemberService;
import com.jeeplus.modules.orders.entity.Orders;
import com.jeeplus.modules.orders.service.OrdersService;
import com.jeeplus.modules.rewardparameters.entity.RewardParameters;
import com.jeeplus.modules.rewardparameters.service.RewardParametersService;
import com.jeeplus.modules.subrecord.entity.SubRecord;
import com.jeeplus.modules.subrecord.service.SubRecordService;
import com.jeeplus.modules.teamservice.service.TeamServiceService;
import com.jeeplus.modules.traderecord.service.TradeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;


/**
 * 用户表Controller
 * @author freedom
 * @version 2019-09-09
 */
@Controller
@RequestMapping(value = "${adminPath}/back")
public class BackendController extends BaseController {

	@Autowired
	private AccountService accountService;
	@Autowired
	private OrdersService ordersService;
	@Autowired
	private MemberService memberService;
	@Autowired
	private DynamicRecordService dynamicRecordService;
	@Autowired
	private TeamServiceService teamServiceService;
	@Autowired
	private TradeRecordService tradeRecordService;
	@Autowired
	private SubRecordService subRecordService;
	@Autowired
	private RewardParametersService rewardParametersService;
	@RequestMapping("search")
	public String search(HttpServletRequest request, HttpServletResponse response, Model model) {
		Double totalBuy = 0.0;             //总认购额
		Double totalStatic = 0.0;          //总成交额
		Double todayBuy = 0.0;             //每日销售认购额
		Integer todayStatic = 0;          //每日增长人数
		Double todayDynamic = 0.0;         //每日发放奖励
		Double todayCost = 0.0;            //每日成交额
		
		totalBuy = subRecordService.getTotalRecord();
		if(totalBuy == null) {
			totalBuy = 0.0;
		}
		model.addAttribute("totalBuy", totalBuy);
		
		totalStatic = tradeRecordService.getTotalSum();
		if(totalStatic == null) {
			totalStatic = 0.0;
		}
		model.addAttribute("totalStatic", totalStatic);
		
		todayStatic = memberService.getTodayNum();
		if(todayStatic == null) {
			todayStatic = 0;
		}
		model.addAttribute("todayStatic", todayStatic);
		
		todayDynamic = accountService.getTodayDynamic();
		if(todayDynamic == null){
			todayDynamic =0.0;
		}
		model.addAttribute("todayDynamic", todayDynamic);

		todayCost = tradeRecordService.getTodayStatic();
		if(todayCost == null){
			todayCost =0.0;
		}
		model.addAttribute("todayCost", todayCost);
		List<RewardParameters> list = rewardParametersService.findList(new RewardParameters());
		if (list.size()>0){
			model.addAttribute("totalIntegral", BigDecimal.valueOf(list.get(0).getTotalIntegral()).setScale(2,BigDecimal.ROUND_HALF_DOWN));
		}else {
			model.addAttribute("totalIntegral", 0);
		}

		todayBuy = subRecordService.getTodayRecord();

		Page<SubRecord> page = subRecordService.findTodayListPage(new Page<SubRecord>(request, response), new SubRecord());
		model.addAttribute("page", page);
		model.addAttribute("todayBuy", todayBuy == null?0:todayBuy);
//		model.addAttribute("todayCost", todayStatic+todayDynamic);
		return "modules/backend/search";
	}
	
	

	

	
	
}